package reduce.fz.com.reduce.util;

import android.view.View;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

import reduce.fz.com.reduce.R;

/**
 * Created by qingshengzheng on 15/7/31.
 */
public class DotUtil {
    private LinearLayout mLinearLayout;
    private List<View> dotViewsList;

    public DotUtil(LinearLayout mLinearLayout) {
        this.mLinearLayout = mLinearLayout;
    }

    public  List<View> createDots(Long size, int wh) {
        dotViewsList = new ArrayList<View>();
        for (int i = 0; i < size; i++) {
            View dot = new View(mLinearLayout.getContext());
            LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(wh, wh);
            layoutParams1.setMargins(wh / 3, 0, wh / 3, 0);
            dot.setLayoutParams(layoutParams1);
            if (i > 0) {
                dot.setBackgroundResource(R.drawable.dot_item);
            } else {
                dot.setBackgroundResource(R.drawable.dot_item_current);
            }
            mLinearLayout.addView(dot);
            dotViewsList.add(dot);
        }
        return dotViewsList;
    }

    public void selectDot(int position) {
        int position1 = position % dotViewsList.size();
        for (
                int i = 0, len = dotViewsList.size();
                i < len; i++)

        {
            if (i == position1) {//current
                dotViewsList.get(i).setBackgroundResource(R.drawable.dot_item_current);
            } else {
                dotViewsList.get(i).setBackgroundResource(R.drawable.dot_item);
            }
        }
    }

}
